#coding=utf-8
#!/usr/bin/python3
# @author:ZhaiGuiDe
# @Time:2021/6/4/ 14:52

"""
删除已经入库的视频
"""
import requests
import threading
from constants import ADMIN_IP, DELETE_VIDEO_URL
from load_video_110_53.db_connect import MysqlClient
from load_video_110_53.load_video_110_53_81 import ADMIN_PORT, ProcessVideo

class DeleteVideo:
    """删除指定上传者上传的时候"""
    def __init__(self):
        self.dbc=MysqlClient()
        self.prv = ProcessVideo()
    def select_video_ids(self,load_video_author):
        #拿到所有该作者上传的视频
        #查询出来固定作者沈上传的视频ID
        select_video_id_by_auth_sql = """
                        SELECT id FROM `video_origin` where create_by='%s';
        """
        video_id_lists = self.dbc.dataSelect(select_video_id_by_auth_sql% (load_video_author))
        return video_id_lists

    def dele_video(self,video_id):
        url = "http://"+ADMIN_IP+":"+ADMIN_PORT + DELETE_VIDEO_URL
        headers = {
            "Accept": "application/json, text/plain, */*",
            "Accept-Encoding": "gzip, deflate",
            "Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8",
            "Cache-Control": "no-cache",
            "Connection": "keep-alive",
            "Host": ADMIN_IP + ":" + ADMIN_PORT,
            "Origin": "http://" + ADMIN_IP + ":" + ADMIN_PORT,
            "Pragma": "no-cache",
            "Referer": "http://" + ADMIN_IP + ":" + ADMIN_PORT + "/admin/",
            "token": self.prv.get_token(),
            "User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4449.6 Safari/537.36",
        }
        # "http://10.168.103.53:81/api/video_analysis/video/delete?ids=9308,9307,9306,9305,9304,9303,9302,9301,9300,9299"

        res = requests.delete(url=url+str(video_id),headers=headers,)
        print(res.json())

if __name__ == '__main__':
    dv = DeleteVideo()
    t_objs = []
    for id in dv.select_video_ids("admin2000"):
        t = threading.Thread(target=dv.dele_video,args=(id[0],))
        t.start()
        t.join()
        # t_objs.append(t)
    # for t in t_objs:


        # dv.dele_video(id[0])

    print("删除完毕")







